//
//  AppDelegate.swift
//  weibo
//
//  Created by 李江波 on 16/10/6.
//  Copyright © 2016年 lijiangbo. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        window = UIWindow()
        
        window?.backgroundColor = UIColor.white
        
        window?.rootViewController = WBMainController()

        window?.makeKeyAndVisible()
        
        loadInfo()
        
        return true
    }

   

}


// MARK: - 模拟加载网络json
extension AppDelegate {

    fileprivate func loadInfo() {
    
        //模拟异步
        DispatchQueue.global().async {
            
            let url = Bundle.main.url(forResource: "main.json", withExtension: nil)
            
            let data = NSData(contentsOf: url!)
            
            //写入磁盘
            let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
            
            let jsonPath = (path as NSString).appendingPathComponent("main.json")
            
            data?.write(toFile: jsonPath, atomically: true)
            
            print("加载完毕\(jsonPath)")
        }
    
    }


}



